<template>
  <div>
    <van-nav-bar
      :title="
        comment.reply_count > 0 ? `${comment.reply_count}条评论` : '暂无评论'
      "
    >
      <van-icon name="cross" slot="left" @click="$emit('close')" />
    </van-nav-bar>
    <div class="scroll-wrap">
      <comment-item :comment="comment"></comment-item>
      <van-cell title="全部评论"></van-cell>
      <comment-list
        :source="comment.com_id"
        type="c"
        :list="commentList"
      ></comment-list>
    </div>
    <div class="reply-bottom">
      <van-button
        class="write-btn"
        size="small"
        round
        @click="isPostShow = true"
        >写评论</van-button
      >
    </div>
    <van-popup v-model="isPostShow" position="bottom">
      <comment-post
        :target="comment.com_id"
        @onpost-success="onPostSuccess"
      ></comment-post>
    </van-popup>
  </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import CommentList from './comment-list.vue'
import CommentPost from './comment-post.vue'

export default {
  name: 'CommentReply',
  props: {
    comment: {
      type: Object,
      require: true
    }
  },
  methods: {
    onPostSuccess (comment) {
      // 关闭弹层
      this.isPostShow = false
      // 评论数量+1
      this.comment.reply_count++
      // 添加数据到列表上面
      this.CommentList.unshift(comment)
    }
  },
  components: { CommentItem, CommentList, CommentPost },
  data () {
    return {
      isPostShow: false, // 新增评论弹层
      commentList: []// 评论列表
    }
  },
  created () {},
  mounted () {},
  watch: {},
  computed: {}
}
</script>

<style lang="less" scoped>
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}
.reply-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .write-btn {
    width: 60%;
  }
}
</style>
